package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.service.AdminServices;

@WebServlet("/DelAdminServlet")
public class DelAdminServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			String id=req.getParameter("id");
			String uid=req.getParameter("uid");
			String state=req.getParameter("state");
			AdminServices adser=new AdminServices();
			PrintWriter out=resp.getWriter();
			if(id!=null){
				int aid=Integer.parseInt(id);	
				int m=adser.delAdmin(aid);				
				if(m>0){
					out.print(1);
				}else{
					out.print(0);
				}
			}else{
				int aid=Integer.parseInt(uid);
				int sta=0;
				if(state.equals("冻结")){
					sta=1;
				}else{
					sta=0;
				}
				int m=adser.update(aid, sta);
				if(m>0){
					out.print(1);
				}else{
					out.print(0);
				}
			}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
